package com.xiangjiayi.study.config;

import com.xiangjiayi.study.listener.TestChatModelListener;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.List;

@Configuration
public class LLMConfig
{
    @Bean(name = "qwen")
    public ChatModel chatModelQwen()
    {
        return OpenAiChatModel.builder()
                    .apiKey(System.getenv("aliQwen-api"))
                    .modelName("qwen-plus")
                    .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                    .logRequests(true) // 日志界别设置为debug才有效
                    .logResponses(true)// 日志界别设置为debug才有效
                    .listeners(List.of(new TestChatModelListener())) //监听器
                    .maxRetries(2)// 重试机制
//                    .timeout(Duration.ofSeconds(3))
                .build();
    }
}
